package com.xiaozhengkeji.springboot.frame.easy.security;

import com.xiaozhengkeji.springboot.frame.easy.entity.SysLog;
import com.xiaozhengkeji.springboot.frame.easy.service.SysLogService;
import com.xiaozhengkeji.springboot.frame.easy.utils.AddressesUtil;
import com.xiaozhengkeji.springboot.frame.easy.utils.XZRedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Slf4j
public class AuthInterceptor extends HandlerInterceptorAdapter {
    //@Autowired
    //private SysLogService sysLogService;

    private XZRedisUtil xzRedisUtil = new XZRedisUtil(1);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //得到请求的URL地址
        //String requestUrl = request.getRequestURL().toString();
        //得到请求的URL地址中附带的参数
        //String queryString = request.getQueryString();
        //得到请求URL地址时使用的方法
        //String method = request.getMethod();
        //String IP = AddressesUtil.getIpAddress(request);
        //String info = "\n访问路径[" + requestUrl + "]\n参数[" + queryString + "]\n访问方式[" + method + "]\n访问者信息:[" + AddressesUtil.getAddersse(IP) + "]";
        //log.info(info);
//        SysLog sysLog = new SysLog();
//        sysLog.setNewDate(new Date());
//        sysLog.setLogs(info);
//        sysLogService.insert(sysLog);
        return true;
    }
}
